package com.goods.controller.business;

import com.goods.business.service.InStockService;
import com.goods.common.response.ResponseBean;
import com.goods.common.utils.JWTUtils;
import com.goods.common.vo.business.InStockDetailVO;
import com.goods.common.vo.business.InStockVO;
import com.goods.common.vo.business.ProductCategoryTreeNodeVO;
import com.goods.common.vo.business.ProductVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author XiaoHong
 * @description 入库接口
 * @date 2022/2/17
 */
@RestController
@Api(tags = "入库接口")
@RequestMapping("/business/inStock")
public class InStockController {
    @Autowired
    private InStockService inStockService;
    //http://www.localhost:8989/business/inStock/findInStockList?pageNum=1&pageSize=10&status=0
    //查询入库列表
    /*
    * InStockVO(id=null, inNum=231232, type=2, operator=null, supplierId=null,
    * supplierName=null, createTime=null, modified=null, productNumber=null, remark=null, products=[],
    *  status=0, startTime=Thu Feb 03 00:00:00 CST 2022, endTime=Fri Mar 04 00:00:00 CST 2022,
    *  name=null, address=null, email=null, phone=null, sort=null, contact=null)
    *
    * */
    @GetMapping("/findInStockList")
    public ResponseBean<PageVO<InStockVO>> findInStockList(@RequestParam("pageNum") Integer pageNum,
            @RequestParam("pageSize") Integer pageSize,InStockVO inStockVO){  //实际上传过来的几个过滤条件用实体类接受了；
        System.out.println(inStockVO);
        PageVO<InStockVO> inStockVOPageVO = inStockService.findInStockList(inStockVO,pageNum,pageSize);
        return ResponseBean.success(inStockVOPageVO);
    }

    //http://www.localhost:8989/business/inStock/remove/112
    //将入库信心移入到回收站
    @PutMapping("/remove/{InStockId}")
    public ResponseBean remove(@PathVariable Long InStockId) {
        inStockService.remove(InStockId);
        return ResponseBean.success();
    }

    //将物资通过审核
    @PutMapping("/publish/{InStockId}")
    public ResponseBean publish(@PathVariable Long InStockId) {
        inStockService.publish(InStockId);
        return ResponseBean.success();
    }

//    http://www.localhost:8989/business/inStock/delete/116
//将入库单删除
@GetMapping("/delete/{InStockId}")
public ResponseBean delete(@PathVariable Long InStockId) {
    inStockService.delete(InStockId);
    return ResponseBean.success();
}

    //将入库信心从回收站恢复
    @PutMapping("/back/{InStockId}")
    public ResponseBean back(@PathVariable Long InStockId) {
        inStockService.back(InStockId);
        return ResponseBean.success();
    }

//    //将入库信心删除
//    @DeleteMapping("/delete/{InStockId}")
//    public ResponseBean delete(@PathVariable Long InStockId) {
//        inStockService.delete(InStockId);
//
//        return ResponseBean.success();
//    }

    //
    //http://www.localhost:8989/business/inStock/addIntoStock
    //{"type":1,"sort":1,"supplierId":"","remark":"122366","address":"河北省/秦皇岛市/长安区",
    // "products":[{"productId":62,"productNumber":2},{"productId":61,"productNumber":1}],
    // "valueProvince":"130000","valueCity":"130300","city":"秦皇岛市","valueOrigin":"130302","origin":"长安区",
    // "province":"河北省","name":"123333","contact":"111111111","email":"54166556@qq.com","phone":"18438004900"}
    //添加新的入库信息
    @PostMapping("/addIntoStock")
    public ResponseBean addIntoStock(@RequestBody InStockVO inStockVO,
                                     @RequestHeader(value = "Authorization",required = false)String token) {
        String username = JWTUtils.getUsername(token);

        inStockService.addIntoStock(inStockVO,username);
        return ResponseBean.success();
    }


    //http://www.localhost:8989/business/inStock/detail/115?pageNum=1
    /*
    *               this.detailTable = res.data.itemVOS;
                    this.detailTotal = res.data.total;
                    this.supplier=res.data.supplierVO;
                    this.pStatus=res.data.status;
                    this.dialogVisible = true;
    *
    * */
    //获取入库记录明细
    @GetMapping("/detail/{id}")
    public ResponseBean<InStockDetailVO> detail(
            @RequestParam("pageNum") Integer pageNum,
            @PathVariable Long id //这个是inStock的主键
    ){
        System.out.println("id:"+id);
        System.out.println("pageNum:"+pageNum);
        InStockDetailVO inStockDetailVO =inStockService.detail(id,pageNum);
        return ResponseBean.success(inStockDetailVO);
    }



}
